const express = require('express');
const router = express.Router();

// 模拟产品数据
let products = [
  { id: 1, name: '产品A', price: 100, category: '电子' },
  { id: 2, name: '产品B', price: 200, category: '家居' },
  { id: 3, name: '产品C', price: 150, category: '电子' }
];

// 获取所有产品
router.get('/', (req, res) => {
  // 支持查询参数过滤
  const { category, minPrice, maxPrice } = req.query;
  let filteredProducts = [...products];

  if (category) {
    filteredProducts = filteredProducts.filter(p => p.category === category);
  }

  if (minPrice) {
    filteredProducts = filteredProducts.filter(p => p.price >= parseInt(minPrice));
  }

  if (maxPrice) {
    filteredProducts = filteredProducts.filter(p => p.price <= parseInt(maxPrice));
  }

  res.json({
    status: 'success',
    data: filteredProducts,
    count: filteredProducts.length
  });
});

// 其他产品相关的API端点...
// 可以根据需要添加更多端点

module.exports = router;